import { get } from "./Axios";

const CACHE_USER_TOKEN = "xyzf_user_token";

export const isAuth = () => {
  const data = localStorage.getItem(CACHE_USER_TOKEN);
  if (data) {
    return true;
  } else {
    return false;
  }
};

export const getLocalPosition = () => {
  const data = JSON.parse(localStorage.getItem("cache_city_msg"));
  if (!data || data.length === 0) {
    const curCity = new window.BMapGL.LocalCity();
    curCity.get((result) => {
      get("/area/info", {
        name: result.name,
      }).then((data) => {
        result.value = data.data.body.value;
        result.label = data.data.body.label;
        localStorage.setItem("cache_city_msg", JSON.stringify(result));
        return result;
      });
    });
  }
  return data;
};
